package logic

import (
	"context"
	"user_srv/model/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginByMobileLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginByMobileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginByMobileLogic {
	return &LoginByMobileLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LoginByMobileLogic) LoginByMobile(in *user.LoginByMobileRequest) (*user.LoginByMobileResponse, error) {
	// todo: 手机号登录

	u := mysql.User{}

	err := u.FindByMobile(in.Mobile)
	if err != nil {
		logx.Error("未查询到手机号", err)
		return nil, err
	}

	return &user.LoginByMobileResponse{UserId: int64(u.ID)}, nil
}
